<?php
namespace Purse\Model;
use Think\Model;
class PurseCashModel extends Model {
	protected $connection = 'DB_BASE_DSN';
	protected $tableName = 'qyx_purse_cash'; 
	
	public function getCashList($data){
		if(!empty($data['custid'])){
			$map['custid']  = $data['custid'];
		}
	
		if($data['status'] !== null){
			$map['status']  = $data['status'];
		}
		
		$total = $this->where($map)->count();
		$total = (int)$total;
		
		if(empty($data['sortField']))$data['sortField'] = "cashid";
		if(empty($data['sortOrder']))$data['sortOrder'] = "asc";
	
		if(empty($data['pageSize']) && empty($data['pageIndex']))
			$result = $this->where($map)->order("{$data['sortField']} {$data['sortOrder']}")->select();
		else
			$result = $this->where($map)->order("{$data['sortField']} {$data['sortOrder']}")->limit($data['pageIndex']*$data['pageSize'] , $data['pageSize'])->select();
	
		return array('total'=>$total , 'data'=>$result);
	}
	
	
	public function getCashById($cashid){
		$map['cashid'] = $cashid;
		$result = $this->where($map)->find();
		return $result;
	}
	
	public function updateCash($data){
		$map['cashid'] = $data['cashid'];
		$result = $this->where($map)->save($data);
		return $result;
	}
	
	public function addCash($data){
		$result = $this->add($data);
		return $result;
	}
}


